<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>学籍列表</title>
</head>
<link href="${pageContext.request.contextPath}/static/core/css/style.css">
<style>
    .modal.fade.in {
        top: 90px;
    }
    .update-census-modal{
        width: 843px !important;

    }
</style>
<body>

<script>
    $(function () {
        /*调用初始模态框的方法*/
        modelDisiplay();
        selectEnrolDisplay();
    });


    function remove(id) {
        var flag = confirm("您确认要执行删除操作？");
        if (flag) window.location.href = _baselocation + "/census/delete/" + id;
    }

    /**
     * 将修改的班级信息传递到后台并且隐藏模态框
     */
    function update() {
        /*获取form表达之后调用sumbit方法传递数据*/
        $("#update-census-form").submit();
        /*隐藏模态框*/
        $('#update-census-modal').modal('hide');
    }

    function onUpdateModal(id) {
        /*获取对应id的班级元素就是一行tr*/
        var _Dom = $('[data-census-code=' + id + ']');
        /*获取对应学籍id*/
        var studentId = _Dom.find(".student-name").attr("data-census-studnet-id");
        /*目标学分*/
        var targetScore = _Dom.find(".target-score").text();
        /*当前获得学分*/
        var currentScore = _Dom.find(".current-score").text();
        /*目标学分*/
        var targetScore = _Dom.find(".target-score ").text();
        /*学籍变动*/
        var schoolEvent = _Dom.find(".school-event").text();
        /*毕业时间*/
        var graduationTime = _Dom.find(".graduation-time").text();
        /*当前年级*/
        var currentEnrol = _Dom.find(".current-enrol").text();
        /*是否有违纪标识*/
        var dangerValid = _Dom.find(".danger-valid").text();
        /*学校评价*/
        var schoolEvaluation = _Dom.find(".school-evaluation").text();
        /*录入老师id*/
        var teacherId = _Dom.find(".teacher-id").attr("data-teacher-id");
        /*在控制台中输出 作用：调试软件*/
        console.log(currentEnrol);
        /*设置表单信息*/
        $(".census-id").val(id);
        $("[name='studentId']").val(studentId.trim());
        $("[name='targetScore']").val(targetScore.trim());
        $("[name='currentScore']").val(currentScore.trim())
        $("[name='schoolEvent']").val(schoolEvent.trim())
        $("[name='graduationTime']").val(graduationTime.trim())
        $("[name='currentEnrol']").val(currentEnrol.trim())
        $("[name='dangerValid']").val(dangerValid.trim())
        $("[name='schoolEvaluation']").val(schoolEvaluation.trim())
        $("[name='teacherId']").val(teacherId.trim())
        /*显示修改模态框*/
        $('#update-census-modal').modal('show');
    }

    function addCensus() {
        window.location.href = _baselocation + "/census/add";
    }

    /**
     * 初始化模态框表单组件
     */
    function modelDisiplay() {
        initModelTeacherSelect()
        initModelStudentSelect()
    }

    /**
     * 初始化模态框中学生下拉列表
     */
    function initModelStudentSelect() {
        $.ajax({
            url: _baselocation + "/student/studentlist/json",
            type: 'post',
            contentType: 'application/json; charset=UTF-8',
            data: null,//一定不能给转成json字符串传过去 结果会是这样""201922101411""
            dataType: "json",
            success: function (result) {
                // console.log(result)
                if (result != null) {
                    for (var i = 0; i < result.length; i++) {
                        $("#student-id").append('<option value=' + result[i].id + '>' + result[i].name + '</option>');
                    }
                }
            },
        });
    }

    /**
     * 初始化模态框中老师下拉列表
     */
    function initModelTeacherSelect() {
        $.ajax({
            url: _baselocation + "/teacher/teacherlist/json",
            type: 'post',
            contentType: 'application/json; charset=UTF-8',
            data: null,//一定不能给转成json字符串传过去 结果会是这样""201922101411""
            dataType: "json",
            success: function (result) {
                // console.log(result)
                if (result != null) {
                    for (var i = 0; i < result.length; i++) {
                        $("#teacher-id").append('<option value=' + result[i].id + '>' + result[i].teacherName + '</option>');
                    }
                }
            },
        });
    }

    /**
     * 初始化年级下拉菜单
     * /enrol/list
     */
    function selectEnrolDisplay() {
        $.ajax({
            url: _baselocation + "/enrol/enrol/list",
            type: 'post',
            contentType: 'application/json; charset=UTF-8',
            data: null,//一定不能给转成json字符串传过去 结果会是这样""201922101411""
            dataType: "json",
            success: function (result) {
                // console.log(result)
                if (result != null) {
                    for (var i = 0; i < result.length; i++) {
                        $("#query-content-current-enrol").append('<option value=' + result[i].enrolName + '>' + result[i].enrolName + '</option>');
                    }
                }
            },
        });
    }
</script>
<!--主容器-->
<div class="row">

    <div class="col-md-12">
        <h1>学籍管理</h1>
        <button type="button" class="add-enrol-btn btn btn-warning" onclick="addCensus()">添加</button>
        <div class="query-content">
            <form class="form-inline" action="${pageContext.request.contextPath}/census/query">
                <div class="form-group">
                    <label for="query-content-graduation-time">毕业时间</label>
                    <input type="date" class="form-control" name="graduationTime"
                           id="query-content-graduation-time">
                </div>
                <div class="form-group">
                    <label for="query-content-current-enrol">所属年级</label>
                    <select class="form-control" name="currentEnrol" id="query-content-current-enrol">
                        <option></option>
                    </select>
                </div>
                <button type="submit" class="btn btn-default">搜索</button>
            </form>
        </div>
        <table class="table table-hover table-bordered">
            <!--表头-->
            <thead>
            <th class="info text-center">学籍编号</th>
            <th class="info text-center">学生名称</th>
            <th class="info text-center">目标获得学分毕业前必须达到的学分</th>
            <th class="info text-center">当前获得学分</th>
            <th class="info text-center">学籍变动说明</th>
            <th class="info text-center">毕业时间</th>
            <th class="info text-center">所属年级</th>
            <th class="info text-center">学校评价</th>
            <th class="info text-center">重大违纪表示</th>
            <th class="info text-center">录入老师名称</th>
            <th class="info text-center">操作</th>
            </thead>
            <!--表内容-->
            <tbody>
            <c:forEach var="obj" items="${voList}" varStatus="index">
                <tr class="text-center" data-census-code="${obj.id}">
                    <td>
                            ${index.count}
                    </td>
                    <td class="student-name" data-census-studnet-id="${obj.studentEntity.id}">
                        <a href="">${obj.studentEntity.name}</a>
                    </td>
                    <td class="target-score">
                            ${obj.targetScore}
                    </td>
                    <td class="current-score">
                            ${obj.currentScore}
                    </td>
                    <td class="school-event">
                            ${obj.schoolEvent}
                    </td>
                    <td class="graduation-time">
                        <fmt:formatDate value="${ obj.graduationTime }" type="date" dateStyle="default"/>
                    </td>
                    <td class="current-enrol">
                            ${obj.currentEnrol}
                    </td>
                    <td class="school-evaluation">
                            ${obj.schoolEvaluation}
                    </td>

                    <td class="danger-valid">
                        ${obj.dangerValid}
                    </td>
                    <td class="teacher-id" data-teacher-id="${obj.teacher.id}">
                            ${obj.teacher.teacherName}
                    </td>
                    <td>
                        <button class="btn btn btn-info" onclick="onUpdateModal(${obj.id})">修改</button>
                        <button class="btn btn btn-danger" onclick="remove(${obj.id})">删除</button>
                    </td>
                </tr>
            </c:forEach>
            </tbody>
        </table>
    </div>
</div>

<!--修改模态框-->
<div class="modal fade" id="update-census-modal" tabindex="10" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">修改学籍信息</h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-md-12">
                        <!--修改区-->
                        <form class="form-horizontal"
                              action="${pageContext.request.contextPath}/census/update" id="update-census-form"
                              method="post">
                            <input type="hidden" name="id" class="census-id">
                            <div class="form-group">
                                <label for="student-id" class="col-sm-2 control-label">学籍绑定</label>
                                <div class="col-sm-10">
                                    <select class="form-control student-id" id="student-id" name="studentId">
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="target-score" class="col-sm-2 control-label">获得学分</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" name="targetScore" id="target-score"
                                           placeholder="请输入目标获得学分毕业前必须达到的学分">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="current-score" class="col-sm-2 control-label">已获得学分</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" name="currentScore" id="current-score"
                                           placeholder="请输入目前获得的学分">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="schoolEvent" class="col-sm-2 control-label">学籍说明</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" name="schoolEvent" id="schoolEvent"
                                           placeholder="请输入电话">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="graduation-time" class="col-sm-2 control-label">毕业时间</label>
                                <div class="col-sm-10">
                                    <input type="date" class="form-control" name="graduationTime"
                                           id="graduation-time">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="current-enrol" class="col-sm-2 control-label">所在年级</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" name="currentEnrol" id="current-enrol"
                                           placeholder="当前所在年级">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="school-evaluation" class="col-sm-2 control-label">学校评价</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" name="schoolEvaluation"
                                           id="school-evaluation"
                                           placeholder="请输入学校评价">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="danger-valid" class="col-sm-2 control-label">是否违纪</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" name="dangerValid" id="danger-valid"
                                           placeholder="重大违纪表示">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="teacher-id" class="col-sm-2 control-label">录入老师</label>
                                <div class="col-sm-10">
                                    <select class="form-control" id="teacher-id" name="teacherId">

                                    </select>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="update()">提交</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

</body>
</html>
